package cn.mw.cmdb.param.zabbixResult;

import cn.mw.cmdb.util.SeverityUtils;
import com.google.common.base.Strings;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import static cn.mw.cmdb.service.impl.InstanceMonitorServiceImpl.*;
import static cn.mw.cmdb.util.ValConvertUtil.*;

@Data
public class MwMonitorItemParam {
    private Object lastvalue;
    //原始的最新值数据
    private Object originalLastValue;
    private String hostid;
    private String itemid;
    private String name;
    private String chName;
    private String units;
    //转换后的单位
    private String convertUnits;
    private String delay;
    private Long sortDelay;
    //    0：数字浮点；1：字符；2：日志；3：数字无符号；4：文字
    private String value_type;
    private Boolean numberFlag;
    private Long sortLastclock;
    private String lastclock;
    private Integer monitorServerId;
    private String valuemapid;
    //    0：正常；1：不支持
    private String state;

    @ApiModelProperty("排序的属性名称")
    private String sortField;
    @ApiModelProperty("0为升序；1为倒序")
    private Integer sortMode;

    public void initParamConvert() {
        if (!Strings.isNullOrEmpty(getLastclock()) && !"0".equals(getLastclock()) ) {
            long time = longValueConvert(getLastclock());
            setSortLastclock(time);
            setLastclock(SeverityUtils.getDate(time));
        } else {
            setLastclock("");
            setSortLastclock(0L);
        }
        if (!Strings.isNullOrEmpty(value_type) && ("3".equals(value_type) || "0".equals(value_type))) {
            //类型0、3表示为数值类型
            setNumberFlag(true);
            if("3".equals(value_type)){
                //3表示数字无符号
                setOriginalLastValue(longValueConvert(lastvalue));
            }
            if("0".equals(value_type)){
                //0数字浮点
                setOriginalLastValue(doubleValueConvert(lastvalue));
            }
        }else{
            setNumberFlag(false);
            setOriginalLastValue(strValueConvert(lastvalue));
        }

        setState(normalState.equals(state) ? normal : unSupported);
        setSortDelay(longValueConvert(getDelayNum(delay)));
    }
}
